package com.mingmen.supplier.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.mingmen.supplier.R;
import com.mingmen.supplier.activity.NewDaiPeiSongDetailActivity;
import com.mingmen.supplier.activity.NewYiWanChengDetailActivity;
import com.mingmen.supplier.adapter.DingDanListAdapter;
import com.mingmen.supplier.model.DingListModel;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

@SuppressLint("ValidFragment")
public class NewYiWanChengListFragment extends BaseFragment implements DingDanListAdapter.OnItemClickListener {
    @BindView(R.id.card_title_tv)
    TextView cardTitleTv;
    Unbinder unbinder;
    private String mTitle;
    //Fragment的View加载完毕的标记
    private boolean isLoading = false;

    //Fragment对用户可见的标记
    private boolean isUIVisible;

    public static NewYiWanChengListFragment getInstance(String title) {
        NewYiWanChengListFragment sf = new NewYiWanChengListFragment();
        sf.mTitle = title;
        return sf;
    }

    @BindView(R.id.recycle_shopo)
    RecyclerView mRecyclerView;
    DingDanListAdapter commodityAdapter;

    List<DingListModel.DataBean> dataList = new ArrayList<>();

    LinearLayoutManager linearLayoutManager;

    @Override
    public View initView() {
        View v = LayoutInflater.from(getActivity()).inflate(R.layout.fr_newdaipeisonglist, null);
        unbinder = ButterKnife.bind(this, v);
        TextView card_title_tv = (TextView) v.findViewById(R.id.card_title_tv);
        card_title_tv.setText(mTitle);

        linearLayoutManager = new LinearLayoutManager(getActivity());

        mRecyclerView.setLayoutManager(linearLayoutManager);
        commodityAdapter = new DingDanListAdapter(getActivity(), dataList);
        mRecyclerView.setAdapter(commodityAdapter);

        mRecyclerView.setVisibility(View.VISIBLE);
        if (dataList.size() > 0) {
            dataList.clear();
        }

        commodityAdapter.setDataList(dataList);
        commodityAdapter.setOnItemClickListener(this);

        commodityAdapter.setOnItemClickListener(new DingDanListAdapter.OnItemClickListener() {
            @Override
            public void onItemClickListener(View view, int pos, List<DingListModel.DataBean> myLiveList) {
                startActivity(new Intent(getActivity(), NewYiWanChengDetailActivity.class));
            }
        });
        return v;
    }

    @Override
    public void initData() {

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.card_title_tv)
    public void onViewClicked() {
    }

    @Override
    public void onItemClickListener(View view, int pos, List<DingListModel.DataBean> myLiveList) {

    }
}